package com.yanqu.road.server.cmd.manor;

import com.yanqu.road.pb.manor.ManorProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.manor.ManorMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/5/25 17:37
 */
@Cmd(code = GameProtocol.S_MANOR_VISIT_OTHER, desc = "庄园拜访其他玩家")
public class ManorVisitOtherCmd extends AbstractCommand {
    private long serverId;
    private long userId;
    private ManorProto.ManorVisitOtherReqMsg msg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        msg = ManorProto.ManorVisitOtherReqMsg.parseFrom(packet.getBytes());
        serverId = msg.getServerId();
        userId = msg.getUserId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (serverId == GameServer.getInstance().getServerId()) {
            ManorProto.ManorVisitOtherRespMsg.Builder respMsg;
            //本服拜访
            respMsg = ManorMgr.getVisitMsg(userId);
            player.sendPacket(ClientProtocol.U_MANOR_VISIT_OTHER, respMsg);
        } else {
            //跨服
            player.sendPacket(CrossProtocol.C_CROSS_VISIT_PLAYER_MANOR, msg.toBuilder());
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
